< previous page page_357 next page >

Page 357
e10a6a0a59f035e870d90cca05b85fce.gif
        Exit Function
    End If
    
    denom = Knot(i + k - 1) - Knot(i)
    If denom = 0 Then
        value1 = 0
    Else
        numer = (t - Knot(i)) * Blend(i, k - 1, t)
        value1 = numer / denom
    End If
     
    denom = Knot(i + k) - Knot(i + 1)
    If denom = 0 Then
        value2 = 0
    Else
        numer = (Knot(i + k) - t) * Blend(i + 1, k - 1, t)
        value2 = numer / denom
    End If
    
    Blend = value1 + value2
End Function
Using function Blend, you can now write functions to compute the X and Y values for the curve. When you write a program that uses these functions to draw the curve, remember that t varies from 0 to N - k + 2 rather than from 0 to 1.
e10a6a0a59f035e870d90cca05b85fce.gif
' The parametric function X(t).
Private Function X(ByVal t As Single) As Single
Dim i As Integer
Dim value As Single

    For i = 0 To MaxPt
         value = value + PtX(i) * Blend(i, Kvalue, t)
    Next i
    X = value
End Function

' The parametric function Y(t).
Private Function Y(ByVal t As Single) As Single
Dim i As Integer
Dim value As Single

    For i = 0 To MaxPt
         value = value + PtY(i) * Blend(i, Kvalue, t)
    Next i
    Y = value
End Function
Example program BSpline uses these functions to draw B-splines. Click with the mouse to create the set of control points. When you click the Go button, the program displays the

 
< previous page page_357 next page >